#ifndef GAMEFILE_H
#define GAMEFILE_H

#include "Graphics.h"
#include "Directinit.h"
#include "D3D9Types.h"


extern "C"
{
	#include "lua.h"
	#include "lualib.h"
	#include "lauxlib.h"
}

typedef enum 
{
	DIR_NODIRECTION = -1,
	DIR_RIGHT = 0,
	DIR_DOWN = 1,
	DIR_LEFT = 2,
	DIR_UP = 3
} Direction_t;

struct SPRITE
{
	int x, y, WalkSpeed;
	int startposx, startposy;
	int frame, columns;
	int width, height;
	float scaling, rotation;
	int startframe, endframe;
	Direction_t direction;
	bool alive;
	float velx, vely;


	SPRITE()
	{
		frame = 0;
		columns = 1;
		width = height = 0;
		scaling = 1.0;
		rotation = 0.0;
		startframe = endframe = 0;
		direction = DIR_DOWN;
		alive = false;
		velx = vely = 0;
	}
};

class Gamefile
{
private:
	Graphics App;
	DirectInit input;
	int score, Counter;
	SPRITE Player, Enemy, Stars[3], Potion;
	int StarsLeft, Invincible;

	char buf[256];
	char level[8][8];
	D3DRECT area;
	Direction_t NextDirection;

public:
	Gamefile();
	~Gamefile();
	bool LoadLevel();
	bool Game_Init(HINSTANCE hInstance, int nCmdShow);	//Initiating the game
	bool Run_Game();
	const char* Convert(int value);	
	bool WallInDirection(SPRITE &spobj, Direction_t dir);
	void movement(SPRITE &spobj);				//Make the player move
	void MoveEnemy(SPRITE &spobj);				//Make enemy move
	int DirectionEnemy(SPRITE spobj, int dir);
	Direction_t Convertdirection(int dir);
	void update();								//Update of keyboard input
	void Shutdown();
	bool Collide(SPRITE &p, SPRITE b);			//Collisiondetection with Sprite/Environment
	int NewDirection();	//Get random direction 
};

#endif
